package com.mysqlconn;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.util.Properties;

/**
 * @author wzm
 * @create 2023-06-12 16:44
 */
//使用德鲁伊获取数据库连接
public class Conn03 {
    public static void main(String[] args) throws Exception {
        //加载配置文件
        Properties properties = new Properties();
        properties.load(Conn03.class.getClassLoader().getResourceAsStream("druid.properties"));

        //获得德鲁伊的datasource
        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);

        //获取连接
        Connection connection = dataSource.getConnection();
        System.out.println("connection = " + connection);


        //关闭连接
        connection.close();//如果是手动获取的close则直接关闭  druid是将连接放回连接池
    }
}
